import axios from 'axios'

const baseUrl = ''
class HttpRequest{
    constructor(baseUrl) {
        this.baseUrl = baseUrl
    }
    getInsideConfig(){
        const config = {
            baseUrl: this.baseUrl,
            header: {}
        }
        return config
    }
    interceptors(instance){
        instance.interceptors.request.use(config => {
            return config
        }, error => {
            return Promise.reject(error)
        })

        instance.interceptors.response.use(response => {
            const {data, code} = response.data
            if(code == 200){
                return data
            }else{

            }
        }, error => {
            return Promise.reject(error)
        })
    }

    request(options){
        const instance = axios.create()
        options = {...this.getInsideConfig(),...options}
        this.interceptors(instance)

        return instance(options)
    }
}

export default new HttpRequest(baseUrl)